package com.epoint.androidphone.mobileoa.ui.webinfo;

import java.util.ArrayList;
import java.util.List;

import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.epoint.androidphone.R;
import com.epoint.androidphone.mobileoa.ui.superview.SuperPhonePage;
import com.epoint.androidmobile.bizlogic.webinfo.model.WebInfo_GetCateGory_Model;
import com.epoint.androidmobile.bizlogic.webinfo.task.WebInfo_GetCateGoryTree_Task;
import com.epoint.androidmobile.bizlogic.webinfo.db.WebInfoDb;
import com.epoint.androidmobile.core.control.AlertUtil;
import com.epoint.androidmobile.core.control.ToastUtil;
import com.epoint.androidmobile.core.string.StringHelp;
import com.epoint.androidmobile.core.xml.XMLUtil;

/**
 * @author liyc
 * @time 2013-5-8 上午10:03:37
 * @annomation 信息阅读栏目列表
 */
public class WebInfoCategoryListView extends SuperPhonePage {

	List<WebInfo_GetCateGory_Model> list = new ArrayList<WebInfo_GetCateGory_Model>();

	CateAdapter adapter = new CateAdapter();
	ListView lv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addContentViewAndTitle(R.layout.webinfocommonlist, getIntentViewTitle());
		lv = (ListView) findViewById(R.id.lv);
		lv.setOnItemClickListener(this);
		list = WebInfoDb.getCategoryListByParentGuid(this,"");
		lv.setAdapter(adapter);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		super.onItemClick(parent, view, position, id);
		final WebInfo_GetCateGory_Model w = list.get(position);
		final List<WebInfo_GetCateGory_Model> listtemp = WebInfoDb.getCategoryListByParentGuid(this,w.CategoryGuid);
		if(listtemp.size()>0)
		{
			list = listtemp;
			adapter.notifyDataSetChanged();
			return;
			/*
			AlertUtil.showAlertMenu(this, "选择", new String[]{"子栏目列表","栏目信息"}, new OnClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which) {
					if(which==0)
					{
						list = listtemp;
						adapter.notifyDataSetChanged();
					}
					else if(which==1)
					{
						Intent intent = new Intent(getContext(), WebInfoListView.class);
						intent.putExtra("categoryguid", w.CategoryGuid);
						intent.putExtra("viewtitle", w.CategoryName);
						startActivity(intent);
					}
				}
			});
			*/
		}
		else{
			Intent intent = new Intent(getContext(), WebInfoListView.class);
			intent.putExtra("categoryguid", w.CategoryGuid);
			intent.putExtra("viewtitle", w.CategoryName);
			startActivity(intent);
		}
	}

	

	class CateAdapter extends BaseAdapter
	{

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			LayoutInflater mInflater = LayoutInflater.from(getContext());
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = mInflater.inflate(R.layout.catelayout, null);
				holder.tvInfo = (TextView) convertView
						.findViewById(R.id.tvInfo);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			holder.tvInfo.setText(list.get(position).CategoryName);
			return convertView;
		}
	}

	class ViewHolder
	{
		public TextView tvInfo;
	}
}
